﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "3.14159";
            radioButton1.Checked = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double x, y;
            FontStyle fontStyle = FontStyle.Regular;

            // 参数验证
            try
            {
                x = double.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("参数必须是数字！");
                textBox1.Text = "";
                textBox1.Focus();
                return;
            }

            // 计算三角函数
            if (radioButton1.Checked)
                y = Math.Sin(x);
            else if (radioButton2.Checked)
                y = Math.Cos(x);
            else
                y = Math.Tan(x);

            // 四舍五入到小数点后2位
            textBox2.Text = Math.Round(y, 2).ToString();

            // 设置字体格式
            if (checkBox1.Checked)
                fontStyle |= FontStyle.Bold;
            if (checkBox2.Checked)
                fontStyle |= FontStyle.Italic;

            textBox2.Font = new Font(textBox2.Font.Name, textBox2.Font.Size, fontStyle);

            // 设置颜色
            if (checkBox3.Checked)
                textBox2.ForeColor = Color.Red;
            else
                textBox2.ForeColor = Color.Black;
        }
    }
}
